/*Author: Ilana M Ventura														  		*/
/*Date: September 2024															  		*/
/*Step 3: Analysis 								  								  		*/
/*		 	 Table 1. Ethnic and racial identification by experimental condition  		*/
/*			 Figure S1. Ethnic and racial Identification by experimental condition		*/
/*		  	 Figure 2. Mean differences in select traits of self-identified American 	*/
/*					Indians, Blacks, Hispanics, Whites and SOR across experimental 		*/
/*					conditions (ref=separate questions format)							*/
/*			 Figure 3. Ethnic and racial identification choices by experimental 		*/
/*					conditions 															*/
/*			 Table 2. Ethnoracial identification of individuals who previously			*/
/*					identified as Hispanic in YouGov�s surveys (Weighted values)		*/



/*Table 1. Ethnic and racial identification by experimental condition*/
/*Figure S1. Ethnic and racial Identification by experimental condition*/
/*NOTE: These two exhibits use the same data*/

proc ttest data=sl_dat plots=none;
	weight weight_genB_13;
	class filter_rand ;
	var Hisp White Black Asian MENA SOR AmIndAN NHoPI Multiracial;
run;

proc ttest data=sl_dat plots=none;
	weight weight_genB_13;
	class filter_rand ;
	var MENA MENA_comb;
run;

Proc means data=sl_dat noprint nway;
	weight weight_genB_13;
	class filter_rand ;
	var Hisp White Black Asian MENA_comb SOR AmIndAN NHoPI Multiracial ;
	output out=Table1 (drop= _type_ _freq_) mean=Hisp White Black Asian MENA SOR AmIndAN NHoPI Multiracial 
				stderr=Hisp_stderr White_stderr Black_stderr Asian_stderr 
						MENA_stderr SOR_stderr AmIndAN_stderr NHoPI_stderr Multiracial_stderr ;
run; 

proc transpose data=Table1 out=Table1;
   by filter_rand;
run;

Data Table1;
	set Table1;
	Race=scan(_name_, 1, '_');
    Type=scan(_name_, 2, '_');
    if type="" then type="Est";
 run;

proc sort data=Table1;  by filter_rand race; run ;
proc transpose data=Table1 out=Table1;
   by filter_rand race;
   var col1;
   id type;
run;

proc sort data=Table1;  by filter_rand DESCENDING  est ; run ;

Data Table1_b;
	set Table1;
	if Race in ("White", "MENA", "SOR") then race2=cats(race, "*");
		else race2= Race;
	if filter_rand=1 then Treatment= "Combined";
		else if filter_rand=2 then Treatment= "Separate";
run;

Data out.Table1; set Table1_b; drop _name_ race; rename race2=race; run;


proc print data= out.Table1 noobs;  run;

/*Figure 2. Mean differences in select traits of self-identified American Indians, 
Blacks, Hispanics, Whites and SOR across experimental conditions (ref=separate questions format)*/

%macro loop(varlist);
%let i=1;
%do %while (%scan(&varlist, &i, |) ^=%str());
%let var=%scan(&varlist, &i, |); 
%put &var;

ods output  ConfLimits=&var._out1  TTests=&var._out2;
proc ttest data=sl_dat;
	weight weight_genB_13;
	Where &var=1;
	class filter_rand ;
	var age_grp_1 age_grp_2 age_grp_3 age_grp_4  
		R_US_Born  R_Born_LatAmSp
		Female Home_owned
		Lang_English Lang_Spanish Lang_Bilingual
		Educ_LT_HS Educ_HS Educ_college 
		Democrat  Republican Independent
		Inc_a Inc_b Inc_c Inc_d 
		skin_light skin_med skin_dark;
run;

proc sort data= &var._out1; by variable method; run;
proc sort data= &var._out2; by variable method; run;

Data &var._out3;
	merge &var._out1 &var._out2;
		by variable method;
	if method="Pooled";
	Group="&var";
	keep Variable Mean LowerCLMean UpperCLMean Probt Group ;
run;


Data &var._means;
	set &var._out1;
	where Class in ("Filter 2a", "Filter 2b");
	Group="&var";
	keep Group variable Class Mean LowerCLMean UpperCLMean ;
run;

%let i=%eval(&i+1);
%end;
%mend;
%let temp=Hisp|White|Black|SOR|AmIndAN;
%loop(&temp);



/*clean and output for figure 2*/
Data out.Fig2;
	set AmIndAN_out3 black_out3
		white_out3
		hisp_out3
		SOR_out3
		
		;
	length Var1 Var2 Group $50.;
	
	if Variable = "Inc_a" then do; Var1="Reported Income"; Var2="Less than $30K"; end;
		if Variable = "Inc_b" then do; Var1="Reported Income"; Var2="$30K-$59K"; end;
		if Variable = "Inc_c" then do; Var1="Reported Income"; Var2="$60K-$99K"; end;
		if Variable = "Inc_d" then do; Var1="Reported Income"; Var2="$100K or more"; end;
	
	if Variable in ("R_Born_LatAmSp") then do; Var1="Nativity"; Var2="Born in LatAm/Sp"; end;
	if Variable in ("Speak_Spanish_Well") then do; Var1="Spanish Speaker"; Var2="."; end;
			
	if Variable in ("Republican", "Independent", "Democrat") then do; 
			Var1="Partisanship"; Var2=Variable; end;
	if Variable = "age_grp_1" then do; Var1="Age Group"; Var2="18-29"; end;
		if Variable = "age_grp_2" then do; Var1="Age Group"; Var2="30-44"; end;
		if Variable = "age_grp_3" then do; Var1="Age Group"; Var2="45-64"; end;
		if Variable = "age_grp_4" then do; Var1="Age Group"; Var2="65+"; end;
	
	if Variable= "skin_dark" then do; Var2="Dark"; 
										Var1="Skin Color Scale"; end;									
	if Variable= "skin_light" then do; Var2="Light"; 
										Var1="Skin Color Scale"; end;									
	if Variable= "skin_med" then do; Var2="Medium"; 
										Var1="Skin Color Scale"; end;

	if Variable= "Lang_Bilingual" then do; Var2="Bilingual"; Var1="Language"; end;
	if Variable= "Lang_English" then do; Var2="English"; Var1="Language"; end;
	if Variable= "Lang_Spanish" then do; Var2="Spanish"; Var1="Language"; end;	
																			
	if Variable= "Female" then do; Var1=Variable; Var2="."; end;
	if Variable= "R_US_Born" then do; Var1="Nativity"; Var2="US Born"; end;
	if Variable= "Home_owned" then do; Var2="."; Var1="Homeownership"; end;
	if Variable= "Educ_LT_HS" then do; Var1="Education"; Var2="Less than HS"; end;
		if Variable= "Educ_college" then do; Var1="Education"; Var2="College"; end;
		if Variable= "Educ_HS" then do; Var1="Education"; Var2="High School"; end;
	if Variable= "Emp_full_time" then do; Var1="Employed Full-time"; Var2="."; end;
	if Group="Asian" and Var1="Language" then delete;
run;

Data out.Fig2_a out.Fig2_b;
	set out.Fig2;
	if Var2 ="."	then output out.Fig2_a;
					else output out.Fig2_b;
run;

ods html close;
ods excel file = "H:\UChicago\Census Experiment\Census Experiment Replication\Replication Files\out\Fig2.xlsx"; /*location for figure 2 data table output*/

proc print data = out.Fig2;
run;

ods excel close;
ods html;


/*Figure 3. Ethnic and racial identification choices by experimental conditions*/

*create "alone" flags;
Data sl_dat;
	set sl_dat;
	if Hisp=1 and sum(White, Black, Asian, AmIndAN, NHoPI, MENA, SOR)=0 then HispAlone=1;
		else if Hisp=1 and sum(White, Black, Asian, AmIndAN, NHoPI, MENA, SOR)>0 then HispAlone=0;
	
	if White =1 and sum(Hisp, Black, Asian, AmIndAN, NHoPI, MENA, SOR)=0 then WhiteAlone=1;
		else if White=1 and sum(Hisp, Black, Asian, AmIndAN, NHoPI, MENA, SOR)>0 then WhiteAlone=0;
		
	if Black=1 and sum(White, Hisp, Asian, AmIndAN, NHoPI, MENA, SOR)=0 then BlackAlone=1;
		else if Black=1 and sum(White, Hisp, Asian, AmIndAN, NHoPI, MENA, SOR)>0 then BlackAlone=0;
		
	if SOR=1 and sum(White, Hisp, Black, Asian, AmIndAN, NHoPI, MENA)=0 then SORAlone=1;
		else if SOR=1 and sum(White, Hisp, Black, Asian, AmIndAN, NHoPI, MENA)>0 then SORAlone=0;
		
	if AmIndAN=1 and sum(White, Hisp, Black, Asian,  NHoPI, MENA, SOR)=0 then AmIndANAlone=1;
		else if AmIndAN=1 and sum(White, Hisp, Black, Asian, NHoPI, MENA, SOR)>0 then AmIndANAlone=0;
	
run;

/*Hisp identification*/
proc means data= sl_dat nway;
	where hisp=1;
	weight weight_genB_13;
	class filter_rand;
	var HispAlone White Black Asian AmIndAN NHoPI MENA SOR;
	output out=fig_3_hisp (drop= _type_ _freq_) mean=HispAlone White Black Asian AmIndAN NHoPI MENA SOR
					stderr=s_HispAlone s_White s_Black s_Asian s_AmIndAN s_NHoPI s_MENA s_SOR;
	title "hisp";
run;


proc transpose data=fig_3_hisp out=fig_3_hisp;
   by filter_rand;
run;

Data fig_3_hisp;
	set fig_3_hisp;
	
	if substr(_name_, 1, 2)='s_' then do;
		type="StdErr";
		Race=substr(_name_, 3);
			end;
		else do;		
			type="Mean";
			race=_name_;
				end;		
		if filter_rand=1 then Group="Combined";
			else Group="Separate";
 run;

proc sort data=fig_3_hisp;  by filter_rand race group; run ;
proc transpose data=fig_3_hisp out=fig_3_hisp (drop=_name_);
   by filter_rand race group;
   var col1;
   id type;
run;


%macro loop(varlist);
%let i=1;
%do %while (%scan(&varlist, &i, |) ^=%str());
%let var=%scan(&varlist, &i, |); 
%put &var;

ods output  TTests=&var._out;
proc ttest data=sl_dat;
	where hisp=1;
	weight weight_genB_13;
	class filter_rand ;
	var  &var;
run;

%if &i=1 %then %do;
Data Hisp_sig;
	set &var._out;
	if method="Pooled";
	if probt = "<.0001" or probt<0.05 then sig="*";
	keep Variable sig Probt  ;
run;
	%end;

%else %if &i GT 1 %then %do;
Data &var._out;
	set &var._out;
	if method="Pooled";
	if probt = <.0001 or probt<0.05 then sig="*";
		else if probt < .1 then sig="+";
	keep Variable sig Probt  ;
run;

Data Hisp_sig; set Hisp_sig  &var._out; run;
	%end;


%let i=%eval(&i+1);
%end;
%mend;
%let temp=HispAlone|White|Black|Asian|AmIndAN|NHoPI|MENA|SOR;
%loop(&temp);

proc sort data=fig_3_hisp; by race; run;
proc sort data=Hisp_sig; by variable; run;

data out.fig3_hisp;
	merge fig_3_hisp (rename=(race=Variable)) hisp_sig;
		by variable;
	Grp=cats(Variable,sig);
	format mean stderr percent8.1;
run;


/**white**/

proc means data= sl_dat nway;
	where White=1;
	weight weight_genB_13;
	class filter_rand;
	var WhiteAlone Hisp Black Asian AmIndAN NHoPI MENA SOR;
	output out=fig_3_White (drop= _type_ _freq_) mean=WhiteAlone Hisp Black Asian AmIndAN NHoPI MENA SOR
					stderr=s_WhiteAlone s_Hisp s_Black s_Asian s_AmIndAN s_NHoPI s_MENA s_SOR;
	title "White";
run;


proc transpose data=fig_3_White out=fig_3_White;
   by filter_rand;
run;

Data fig_3_White;
	set fig_3_White;
	
	if substr(_name_, 1, 2)='s_' then do;
		type="StdErr";
		Race=substr(_name_, 3);
			end;
		else do;		
			type="Mean";
			race=_name_;
				end;		
		if filter_rand=1 then Group="Combined";
			else Group="Separate";
 run;

proc sort data=fig_3_White;  by filter_rand race group; run ;
proc transpose data=fig_3_White out=fig_3_White (drop=_name_);
   by filter_rand race group;
   var col1;
   id type;
run;


%macro loop(varlist);
%let i=1;
%do %while (%scan(&varlist, &i, |) ^=%str());
%let var=%scan(&varlist, &i, |); 
%put &var;

ods output  TTests=&var._out;
proc ttest data=sl_dat;
	where White=1;
	weight weight_genB_13;
	class filter_rand ;
	var  &var;
run;

%if &i=1 %then %do;
Data White_sig;
	set &var._out;
	if method="Pooled";
	if probt = "<.0001" or probt<0.05 then sig="*";
	keep Variable sig Probt  ;
run;
	%end;

%else %if &i GT 1 %then %do;
Data &var._out;
	set &var._out;
	if method="Pooled";
	if probt = <.0001 or probt<0.05 then sig="*";
		else if probt < .1 then sig="+";
	keep Variable sig Probt  ;
run;

Data White_sig; set White_sig  &var._out; run;
	%end;


%let i=%eval(&i+1);
%end;
%mend;
%let temp=WhiteAlone|Hisp|Black|Asian|AmIndAN|NHoPI|MENA|SOR;
%loop(&temp);

proc sort data=fig_3_White; by race; run;
proc sort data=White_sig; by variable; run;

data out.fig3_White;
	merge fig_3_White (rename=(race=Variable)) White_sig;
		by variable;
	Grp=cats(Variable,sig);
	format mean stderr percent8.1;
run;



/**Black**/
proc means data= sl_dat nway;
	where Black=1;
	weight weight_genB_13;
	class filter_rand;
	var BlackAlone Hisp White Asian AmIndAN NHoPI MENA SOR;
	output out=fig_3_Black (drop= _type_ _freq_) mean=BlackAlone Hisp White Asian AmIndAN NHoPI MENA SOR
					stderr=s_BlackAlone s_Hisp s_White  s_Asian s_AmIndAN s_NHoPI s_MENA s_SOR;
	title "Black";
run;


proc transpose data=fig_3_Black out=fig_3_Black;
   by filter_rand;
run;

Data fig_3_Black;
	set fig_3_Black;
	
	if substr(_name_, 1, 2)='s_' then do;
		type="StdErr";
		Race=substr(_name_, 3);
			end;
		else do;		
			type="Mean";
			race=_name_;
				end;		
		if filter_rand=1 then Group="Combined";
			else Group="Separate";
 run;

proc sort data=fig_3_Black;  by filter_rand race group; run ;
proc transpose data=fig_3_Black out=fig_3_Black (drop=_name_);
   by filter_rand race group;
   var col1;
   id type;
run;


%macro loop(varlist);
%let i=1;
%do %while (%scan(&varlist, &i, |) ^=%str());
%let var=%scan(&varlist, &i, |); 
%put &var;

ods output  TTests=&var._out;
proc ttest data=sl_dat;
	where Black=1;
	weight weight_genB_13;
	class filter_rand ;
	var  &var;
run;

%if &i=1 %then %do;
Data Black_sig;
	set &var._out;
	if method="Pooled";
	if probt = "<.0001" or probt<0.05 then sig="*";
	keep Variable sig Probt  ;
run;
	%end;

%else %if &i GT 1 %then %do;
Data &var._out;
	set &var._out;
	if method="Pooled";
	if probt = <.0001 or probt<0.05 then sig="*";
		else if probt < .1 then sig="+";
	keep Variable sig Probt  ;
run;

Data Black_sig; set Black_sig  &var._out; run;
	%end;


%let i=%eval(&i+1);
%end;
%mend;
%let temp=BlackAlone|Hisp|White|Asian|AmIndAN|NHoPI|MENA|SOR;
%loop(&temp);

proc sort data=fig_3_Black; by race; run;
proc sort data=Black_sig; by variable; run;

data out.fig3_Black;
	merge fig_3_Black (rename=(race=Variable)) Black_sig;
		by variable;
	Grp=cats(Variable,sig);
	format mean stderr percent8.1;
run;


/**SOR**/
proc means data= sl_dat nway;
	where SOR=1;
	weight weight_genB_13;
	class filter_rand;
	var SORAlone Hisp White Asian AmIndAN NHoPI MENA Black;
	output out=fig_3_SOR (drop= _type_ _freq_) mean=SORAlone Hisp White Asian AmIndAN NHoPI MENA Black
					stderr=s_SORAlone s_Hisp s_White  s_Asian s_AmIndAN s_NHoPI s_MENA s_Black;
	title "SOR";
run;


proc transpose data=fig_3_SOR out=fig_3_SOR;
   by filter_rand;
run;

Data fig_3_SOR;
	set fig_3_SOR;
	
	if substr(_name_, 1, 2)='s_' then do;
		type="StdErr";
		Race=substr(_name_, 3);
			end;
		else do;		
			type="Mean";
			race=_name_;
				end;		
		if filter_rand=1 then Group="Combined";
			else Group="Separate";
 run;

proc sort data=fig_3_SOR;  by filter_rand race group; run ;
proc transpose data=fig_3_SOR out=fig_3_SOR (drop=_name_);
   by filter_rand race group;
   var col1;
   id type;
run;


%macro loop(varlist);
%let i=1;
%do %while (%scan(&varlist, &i, |) ^=%str());
%let var=%scan(&varlist, &i, |); 
%put &var;

ods output  TTests=&var._out;
proc ttest data=sl_dat;
	where SOR=1;
	weight weight_genB_13;
	class filter_rand ;
	var  &var;
run;

%if &i=1 %then %do;
Data SOR_sig;
	set &var._out;
	if method="Pooled";
	if probt = "<.0001" or probt<0.05 then sig="*";
	keep Variable sig Probt  ;
run;
	%end;

%else %if &i GT 1 %then %do;
Data &var._out;
	set &var._out;
	if method="Pooled";
	if probt = <.0001 or probt<0.05 then sig="*";
		else if probt < .1 then sig="+";
	keep Variable sig Probt  ;
run;

Data SOR_sig; set SOR_sig  &var._out; run;
	%end;


%let i=%eval(&i+1);
%end;
%mend;
%let temp=SORAlone|Hisp|White|Asian|AmIndAN|NHoPI|MENA|Black;
%loop(&temp);

proc sort data=fig_3_SOR; by race; run;
proc sort data=SOR_sig; by variable; run;

data out.fig3_SOR;
	merge fig_3_SOR (rename=(race=Variable)) SOR_sig;
		by variable;
	Grp=cats(Variable,sig);
	format mean stderr percent8.1;
run;


/**Indig**/

proc means data= sl_dat nway;
	where AmIndAN=1;
	weight weight_genB_13;
	class filter_rand;
	var AmIndANAlone Hisp White Asian SOR NHoPI MENA Black;
	output out=fig_3_AmIndAN (drop= _type_ _freq_) mean=AmIndANAlone Hisp White Asian SOR NHoPI MENA Black
					stderr=s_AmIndANAlone s_Hisp s_White  s_Asian s_SOR s_NHoPI s_MENA s_Black;
	title "AmIndAN";
run;


proc transpose data=fig_3_AmIndAN out=fig_3_AmIndAN;
   by filter_rand;
run;

Data fig_3_AmIndAN;
	set fig_3_AmIndAN;
	
	if substr(_name_, 1, 2)='s_' then do;
		type="StdErr";
		Race=substr(_name_, 3);
			end;
		else do;		
			type="Mean";
			race=_name_;
				end;		
		if filter_rand=1 then Group="Combined";
			else Group="Separate";
 run;

proc sort data=fig_3_AmIndAN;  by filter_rand race group; run ;
proc transpose data=fig_3_AmIndAN out=fig_3_AmIndAN (drop=_name_);
   by filter_rand race group;
   var col1;
   id type;
run;


%macro loop(varlist);
%let i=1;
%do %while (%scan(&varlist, &i, |) ^=%str());
%let var=%scan(&varlist, &i, |); 
%put &var;

ods output  TTests=&var._out;
proc ttest data=sl_dat;
	where AmIndAN=1;
	weight weight_genB_13;
	class filter_rand ;
	var  &var;
run;

%if &i=1 %then %do;
Data AmIndAN_sig;
	set &var._out;
	if method="Pooled";
	if probt = "<.0001" or probt<0.05 then sig="*";
	keep Variable sig Probt  ;
run;
	%end;

%else %if &i GT 1 %then %do;
Data &var._out;
	set &var._out;
	if method="Pooled";
	if probt = <.0001 or probt<0.05 then sig="*";
		else if probt < .1 then sig="+";
	keep Variable sig Probt  ;
run;

Data AmIndAN_sig; set AmIndAN_sig  &var._out; run;
	%end;


%let i=%eval(&i+1);
%end;
%mend;
%let temp=AmIndANAlone|Hisp|White|Asian|SOR|NHoPI|MENA|Black;
%loop(&temp);

proc sort data=fig_3_AmIndAN; by race; run;
proc sort data=AmIndAN_sig; by variable; run;

data out.fig3_AmIndAN;
	merge fig_3_AmIndAN (rename=(race=Variable)) AmIndAN_sig;
		by variable;
	Grp=cats(Variable,sig);
	format mean stderr percent8.1;
run;


/*create abbreviated version*/

data out.fig3_white_abrv; set out.fig3_white;
	if Variable in ("NHoPI", "SOR") then delete;
run;

data out.fig3_black_abrv; set out.fig3_black;
	if Variable in ("Asian", "MENA", "NHoPI", "SOR") then delete;
run;

data out.fig3_hisp_abrv; set out.fig3_hisp;
	if Variable in ( "MENA", "NHoPI" ) then delete;
run;

data out.fig3_sor_abrv; set out.fig3_sor;
	if Variable in ("Asian") then delete;
run;

data out.fig3_amindan_abrv; set out.fig3_amindan;
	if Variable in ("MENA", "NHoPI" ) then delete;
run;

/*create data table*/

proc transpose data= out.fig3_hisp out=dt_hisp_m prefix=Mean_;
	by variable sig;
	var mean ;
	id Group;
run;

proc transpose data= out.fig3_hisp out=dt_hisp_s prefix=SE_;
	by variable sig;
	var stderr ;
	id Group;
run;

data dt_hisp;
	retain Group variable mean_combined se_combined mean_separate se_separate sig;
	merge dt_hisp_m dt_hisp_s;
		by variable sig;
	drop _name_;
	Group="Hispanic";
run;

proc print data= dt_hisp noobs; run;

proc transpose data= out.fig3_White out=dt_White_m prefix=Mean_;
	by variable sig;
	var mean ;
	id Group;
run;

proc transpose data= out.fig3_White out=dt_White_s prefix=SE_;
	by variable sig;
	var stderr ;
	id Group;
run;

data dt_White;
	retain Group variable mean_combined se_combined mean_separate se_separate sig;
	merge dt_White_m dt_White_s;
		by variable sig;
	drop _name_;
	Group="White";
run;

proc print data= dt_White noobs; run;


proc transpose data= out.fig3_Black out=dt_Black_m prefix=Mean_;
	by variable sig;
	var mean ;
	id Group;
run;

proc transpose data= out.fig3_Black out=dt_Black_s prefix=SE_;
	by variable sig;
	var stderr ;
	id Group;
run;

data dt_Black;
	retain Group variable mean_combined se_combined mean_separate se_separate sig;
	merge dt_Black_m dt_Black_s;
		by variable sig;
	drop _name_;
	Group="Black";
run;

proc print data= dt_Black noobs; run;


proc transpose data= out.fig3_SOR out=dt_SOR_m prefix=Mean_;
	by variable sig;
	var mean ;
	id Group;
run;

proc transpose data= out.fig3_SOR out=dt_SOR_s prefix=SE_;
	by variable sig;
	var stderr ;
	id Group;
run;

data dt_SOR;
	retain Group variable mean_combined se_combined mean_separate se_separate sig;
	merge dt_SOR_m dt_SOR_s;
		by variable sig;
	drop _name_;
	Group="SOR";
run;

proc print data= dt_SOR noobs; run;


proc transpose data= out.fig3_amindan out=dt_amindan_m prefix=Mean_;
	by variable sig;
	var mean ;
	id Group;
run;

proc transpose data= out.fig3_amindan out=dt_amindan_s prefix=SE_;
	by variable sig;
	var stderr ;
	id Group;
run;

data dt_amindan;
	retain Group variable mean_combined se_combined mean_separate se_separate sig;
	merge dt_amindan_m dt_amindan_s;
		by variable sig;
	drop _name_;
	Group="AmIndAN";
run;

proc print data= dt_amindan noobs; run;



ods html close;
ods excel file = "H:\UChicago\Census Experiment\Census Experiment Replication\Replication Files\out\Fig3.xlsx"; /*location for figure 3 data table output*/

proc print data= dt_hisp noobs; run;
proc print data= dt_White noobs; run;
proc print data= dt_Black noobs; run;
proc print data= dt_SOR noobs; run;
proc print data= dt_amindan noobs; run;

ods excel close;
ods html;




/************YouGov vs Census********************/
/*Table 2. Ethnoracial identification of individuals who 
previously identified as Hispanic in YouGov�s surveys (Weighted values)*/

proc means data= sl_dat nway noprint ;
	weight weight_genB_13; 
	class Racegroup filter_rand ;
	var  White Hisp Black Asian MENA SOR AmIndAN NHoPI Multiracial;
	output out=yougov_compare mean=White Hisp Black Asian MENA SOR AmIndAN NHoPI Multiracial;
run;

proc transpose data= yougov_compare out=yougov_compare_t;
	by Racegroup;
	var White Hisp Black Asian MENA SOR AmIndAN NHoPI Multiracial;
	id filter_rand;
run;

Data yougov_compare_t;
	set yougov_compare_t;
	rename racegroup=YouGovID
		_name_=SelectedRace
		Filter_2a=Combined
		Filter_2b=Separate;
	format _numeric_ percent8.1;
run;

proc print data= yougov_compare_t noobs; run;

proc sort data= sl_dat; by Racegroup; run;
proc ttest data= sl_dat  plots=none;
	weight weight_genB_13; 
	by Racegroup;
	class  filter_rand ;
	var  White Hisp Black Asian MENA SOR AmIndAN NHoPI Multiracial;
run;

Data out.Table2; set yougov_compare_t; run;


	 
